package com.fudan.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.fudan.dto.entities.Question;
import com.fudan.dto.entities.Room;
import com.fudan.dto.entities.User;
import com.fudan.service.QuestionServiceImpl;
import com.fudan.service.RoomServiceImpl;
import com.fudan.service.UserServiceImpl;

@RestController
@RequestMapping("/admin")
@CrossOrigin(origins = "http://localhost:4200")
public class AdminController {
	
	@Autowired
	private UserServiceImpl userService;
	
	@Autowired
	private QuestionServiceImpl questionService;
	
	@Autowired
	private RoomServiceImpl roomService;
	
	@GetMapping("/createDummyData")
    @ResponseBody
	public String createDummyData() {
		
		User liuhao = userService.createStudent("刘浩","1234");
		User gaoTeacher = userService.createTeacher("高老师","1234");
		User wangTeacher = userService.createTeacher("王老师","1234");
		User zhangSan = userService.createStudent("张三","1234");
		User zhangSi = userService.createStudent("张四","1234");
		User zhangWu = userService.createStudent("张五","1234");
		
		
		Room room1 = new Room("现代Web", wangTeacher );
		
		
		
		room1.getUsers().add(zhangSan);
		room1.getUsers().add(zhangSi);
		room1.getUsers().add(zhangWu);
		
		Question question1 = new Question("老师能讲一下xsl的作用吗？", zhangSan);
		Question question2 = new Question("老师能讲一下xsl的作用吗？", zhangSi);
		Question question3 = new Question("老师能讲一下xsl的作用吗？", zhangWu);
		
		room1.getQuestions().add(question1);
		room1.getQuestions().add(question2);
		room1.getQuestions().add(question3);
		
		Room room2 = new Room("人工智能", gaoTeacher );
		room2.getUsers().add(zhangSan);
		room2.getUsers().add(zhangWu);
		
		roomService.updateRoom(room1);
		roomService.updateRoom(room2);
		
		return "success";
	}
	

}
